import request from './request'

/**
 * 上传单个文件
 */
export const uploadFile = (file, path = '', storageType = 'minio') => {
  const formData = new FormData()
  formData.append('file', file)
  formData.append('path', path)
  formData.append('storageType', storageType)
  
  return request({
    url: '/file/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 批量上传文件
 */
export const batchUploadFiles = (files, path = '', storageType = 'minio') => {
  const formData = new FormData()
  files.forEach(file => {
    formData.append('files', file)
  })
  formData.append('path', path)
  formData.append('storageType', storageType)
  
  return request({
    url: '/file/batch-upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 删除文件
 */
export const deleteFile = (fileId) => {
  return request({
    url: `/file/${fileId}`,
    method: 'delete'
  })
}

/**
 * 获取文件信息
 */
export const getFileInfo = (fileId) => {
  return request({
    url: `/file/${fileId}`,
    method: 'get'
  })
}

/**
 * 获取用户上传的文件列表
 */
export const getUserFiles = (userId) => {
  return request({
    url: `/file/user/${userId}`,
    method: 'get'
  })
}
